package com.stlm2.controller;

import com.stlm2.dems.service.DdmShoppingCartService;
import com.stlm2.util.codecontent.CodeContent;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Author：fuchunyu
 * Date：2017/10/20
 * Description：
 */
@Controller
@RequestMapping(("/ShoppingCartC"))
public class DdmShoppingCartController {
    @Resource
    private DdmShoppingCartService shoppingCartService;
    /*
        * 用户获取购物车信息
        *  @param  token
        *   @param  isSettlement:是否结算
         */
    @ResponseBody
    @RequestMapping(value="/getUserShoppingCart.json",produces="application/json;charset=UTF-8")
    public String getUserShoppingCart(String companyCode,ModelMap model, String token, boolean isSettlement){
        String data=null;
        try {
            data=shoppingCartService.getUserShoppingCart(model,token,isSettlement);
        }catch (Exception e){
            e.printStackTrace();

            return  CodeContent.getModelByCode(0,"获取购物车信息失败" ,data);
        }
        return data;
    }


    /*
    * 用户添加购物车
    *  @param  token
    *  @param  goodsId：商品ID
    *  @param count ：数量
    *  @param  specificationId：规格ID（无规格时，可为空）
    *  @param valueAddedServicesIds:增值服务ID，（没有可为空，多个用，隔开）
     */
    @ResponseBody
    @RequestMapping(value="/addUserShoppingCart.json",produces="application/json;charset=UTF-8")
    public String addUserShoppingCart(String companyCode,ModelMap model, String token,String goodsId,String count,String specificationId,String valueAddedServicesIds){
        String data=null;
        try {
            data=shoppingCartService.addUserShoppingCart(model,token,goodsId,count,specificationId,valueAddedServicesIds);
        }catch (Exception e){
            e.printStackTrace();

            return  CodeContent.getModelByCode(0,"添加购物车信息失败" ,data);
        }
        return data;
    }
    /*
    * 用户修改购物车
    *  @param  token
    *  @param  modifydata: 字符串拼接的数据： id=:count=:specificationId=:valueAddedServicesIds= 多组数据以; 隔开
     */
    @ResponseBody
    @RequestMapping(value="/modifyUserShoppingCart.json",produces="application/json;charset=UTF-8")
    public String  modifyUserShoppingCart(String companyCode,ModelMap model, String token,String modifydata){
        String data=null;
        try {
            data=shoppingCartService.modifyUserShoppingCart(model,token,modifydata);
        }catch (Exception e){
            e.printStackTrace();

            return  CodeContent.getModelByCode(0,"修改购物车信息失败" ,data);
        }
        return data;
    }
    /*
    * 用户删除购物车
    *  @param  token
    *  id:ID(多个ID用，拼接)
     */
    @ResponseBody
    @RequestMapping(value="/deleteUserShoppingCart.json",produces="application/json;charset=UTF-8")
    public String deleteUserShoppingCart(String companyCode,ModelMap model,String token,String id){
        String data=null;
        try {
            data=shoppingCartService.deleteUserShoppingCart(model,token,id);
        }catch (Exception e){
            e.printStackTrace();

            return  CodeContent.getModelByCode(0,"删除购物车信息失败" ,data);
        }
        return data;
    }

    /*
    * 用户选择购物车
    *  @param  token
    *  @param  id:ID
    *   @param  option:选项  true:选择 false：未选
    *   valueAddedServicesIds:增值服务拼接的字符串
     */
    @ResponseBody
    @RequestMapping(value="/optionCart.json",produces="application/json;charset=UTF-8")
    public String optionCart(String companyCode,ModelMap model,String token,String id,boolean option,String valueAddedServicesIds){
        String data=null;
        try {
            data=shoppingCartService.optionCart(model,token,id,option,valueAddedServicesIds);
        }catch (Exception e){
            e.printStackTrace();

            return  CodeContent.getModelByCode(0,"选择购物车信息失败" ,data);
        }
        return data;
    }

    	/*
*zlq
* 用户修改购物车
*  @param  token
*  @param  id:
*  @param  count: 数量
 */

    @ResponseBody
    @RequestMapping(value="/modifyCount.json",produces="application/json;charset=UTF-8")
    public String modifyCount(String companyCode,ModelMap model, String token,String id,String count){
        String data=null;
        try {
            data=shoppingCartService.modifyCount(model,token,id,count);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"修改失败" ,data);
        }
        return data;
    }


        	/*
*zlq
* 用户全选购物车
*  @param  token
*  @param  isSelect: 是否选择 ：true：false
*
 */

    @ResponseBody
    @RequestMapping(value="/allSelect.json",produces="application/json;charset=UTF-8")
    public String allSelect(String companyCode,ModelMap model, String token,boolean isSelect){
        String data=null;
        try {
            data=shoppingCartService.allSelect(model,token,isSelect);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"修改失败" ,data);
        }
        return data;
    }
}
